import {defineStore} from "pinia";
export const useTokenStore = defineStore("useTokenStore",()=>{
    let storage = localStorage.getItem("TOKEN")
    let userinfo = localStorage.getItem("userinfo")
    const token = {
        value: '',
        userinfo: {},
    }
    if (storage) token.value = storage
    if (userinfo) token.userinfo = JSON.parse(userinfo)
    function updateUserInfo(data){
        localStorage.setItem('userinfo',JSON.stringify(data))
        token.userinfo = data
    }
    function updateToken(token){
        localStorage.setItem("TOKEN", token)
        token.value = token
    }
    function getUserInfo(){
        return token.userinfo
    }
    function getToken() {
        return token.value
    }
    return {
        getToken,
        getUserInfo,
        updateUserInfo,
        updateToken
    }
},true)